package com.lagou.service;

import com.lagou.entity.COrder;
import com.lagou.repository.COrderRepository;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Date;
import java.util.UUID;

/**
 * @author jinshanzhang
 * @version 1.0
 * @description
 * @date 2021/11/1 6:01 下午
 */
@Service
public class PayService {

    @Autowired
    private COrderRepository cOrderRepository;

    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 创建订单
     * @param cOrder
     * @return
     */
    public String createOrder(@RequestBody COrder cOrder){
        String orderId = UUID.randomUUID().toString();
        cOrder.setOrderId(orderId);
        cOrder.setStatus("10");
        cOrder.setCreateTime(new Date());
        cOrder.setUpdateTime(new Date());
        cOrder.setIsDel(Boolean.FALSE);
        cOrderRepository.save(cOrder);
        // 发送MQ
        rabbitTemplate.convertAndSend("exchange.pay.waiting", "pay.waiting", orderId);
        return orderId;
    }
}
